﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.d80_zyhzMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void d80_zyhz_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            d80_zyhzMgr mgr = new d80_zyhzMgr();
            e.Total = int.Parse(mgr.GetRecordCount_d80_zyhz(e.Parameters[d80_zyhz_Filter.ParamPrefix]));
            IList<d80_zyhz> list = mgr.FindAllByPage_d80_zyhz(e.Start.ToString(), e.Limit.ToString(), e.Parameters[d80_zyhz_Filter.ParamPrefix]);
            d80_zyhz_MainStore.DataSource = list;
            d80_zyhz_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            d80_zyhzMgr mgr = new d80_zyhzMgr();
            RowSelectionModel sm = d80_zyhz_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                d80_zyhz _d80_zyhz = new d80_zyhz();
                _d80_zyhz.id = int.Parse(row.RecordID);
                if (mgr.Del_d80_zyhz(_d80_zyhz))
                {
                    log.Debug("d80_zyhz中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            d80_zyhz_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            d80_zyhzMgr mgr = new d80_zyhzMgr();
            d80_zyhz _d80_zyhz = new d80_zyhz();
            if (Hid.Text.Length > 0)
                _d80_zyhz = mgr.FindById_d80_zyhz(int.Parse(Hid.Text));
            
			_d80_zyhz.grbm = Txtgrbm.Text.Trim();
			_d80_zyhz.dzbm = Txtdzbm.Text.Trim();
			_d80_zyhz.hbh = Txthbh.Text.Trim();
			_d80_zyhz.hsx = Txthsx.Text.Trim();
			_d80_zyhz.chsx = Txtchsx.Text.Trim();
			_d80_zyhz.rbh = Txtrbh.Text.Trim();
			_d80_zyhz.xm = Txtxm.Text.Trim();
			_d80_zyhz.sfzh = Txtsfzh.Text.Trim();
			_d80_zyhz.ylzh = Txtylzh.Text.Trim();
			_d80_zyhz.zbh = Txtzbh.Text.Trim();
			_d80_zyhz.cbh = Txtcbh.Text.Trim();
			_d80_zyhz.xb = Txtxb.Text.Trim();
			_d80_zyhz.brnl = Txtbrnl.Text.Trim();
			_d80_zyhz.csrq = Txtcsrq.Text.Trim();
			_d80_zyhz.hyzk = Txthyzk.Text.Trim();
			_d80_zyhz.mz = Txtmz.Text.Trim();
			_d80_zyhz.csd = Txtcsd.Text.Trim();
			_d80_zyhz.szdq = Txtszdq.Text.Trim();
			_d80_zyhz.jkzk = Txtjkzk.Text.Trim();
			_d80_zyhz.hzgx = Txthzgx.Text.Trim();
			_d80_zyhz.gzdw = Txtgzdw.Text.Trim();
			_d80_zyhz.zy = Txtzy.Text.Trim();
			_d80_zyhz.chsj = Txtchsj.Text.Trim();
			_d80_zyhz.grjf = Txtgrjf.Text.Trim();
			_d80_zyhz.mzyl = Txtmzyl.Text.Trim();
			_d80_zyhz.zzbm = Txtzzbm.Text.Trim();
			_d80_zyhz.zzje = Txtzzje.Text.Trim();
			_d80_zyhz.ljmzfy = Txtljmzfy.Text.Trim();
			_d80_zyhz.ljmzbc = Txtljmzbc.Text.Trim();
			_d80_zyhz.ljzyfy = Txtljzyfy.Text.Trim();
			_d80_zyhz.ljzybc = Txtljzybc.Text.Trim();
			_d80_zyhz.zycs = Txtzycs.Text.Trim();
			_d80_zyhz.mblx1 = Txtmblx1.Text.Trim();
			_d80_zyhz.mblx2 = Txtmblx2.Text.Trim();
			_d80_zyhz.dqzt = Txtdqzt.Text.Trim();
			_d80_zyhz.rcbz = Txtrcbz.Text.Trim();
			_d80_zyhz.rcsj = Txtrcsj.Text.Trim();
			_d80_zyhz.rqyy = Txtrqyy.Text.Trim();
			_d80_zyhz.nn = Txtnn.Text.Trim();
			_d80_zyhz.jgdm = Txtjgdm.Text.Trim();
			_d80_zyhz.mxbz = Txtmxbz.Text.Trim();
			_d80_zyhz.hzxm = Txthzxm.Text.Trim();
			_d80_zyhz.ljzykb = Txtljzykb.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_d80_zyhz(_d80_zyhz);
            else
                isok = mgr.Add_d80_zyhz(_d80_zyhz);
            if (isok)
            {
                d80_zyhz_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("d80_zyhz中执行了保存（插入或修改），并成功");
                d80_zyhz_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}